using System;
using System.Configuration;
using BoxBinary.AspectCache.Core.PolicyDefinition;

namespace BoxBinary.AspectCache.Core.ConfigurationMappers
{
    /// <summary>
    /// A cache category configuration element.
    /// </summary>
    [Serializable]
    public class CachePolicySpecification : ConfigurationElement
    {
        public CachePolicySpecification()
        {
        }

        /// <summary>
        /// Constructs a <see cref="CachePolicySpecification"/> from a key and a set of <see cref="CacheItemFootprint"/> flags.
        /// </summary>
        /// <param name="key"></param>
        /// <param name="footprint"></param>
        public CachePolicySpecification(string key, CacheItemFootprint footprint) : this()
        {
            Key = key;
            Footprint = footprint;
        }

        /// <summary>
        /// <para>Gets or sets the Key of the CachePolicySpecification. Note that the following characters are not allowed: <value> ~!@#$%^&*()[]{}/;'"|\</value></para>
        /// <para>This is used as the key of an item when used in a collection of <see cref="CachePolicySpecification"/> objects.</para>
        /// <para>The default value is <code>interestKey</code></para>
        /// <para>This is a required value.</para>
        /// </summary>
        [StringValidator(InvalidCharacters = " ~!@#$%^&*()[]{}/;'\"|\\"),
         ConfigurationProperty("key", DefaultValue = "interestKey", IsKey = true, IsRequired = true)]
        public string Key
        {
            get { return ((string) (base["key"])); }
            set { base["key"] = value; }
        }

        /// <summary>
        /// <para>Gets or sets the Footprint of the <see cref="CachePolicySpecification"/>.</para>
        /// <para>The default value is <value><see cref="CacheItemFootprint.MediumChangeFrequency"/>,<see cref="CacheItemFootprint.MediumCreationExpense"/>,<see cref="CacheItemFootprint.LowHeapRequirement"/></value>.</para>
        /// <para>This is a required value.</para>
        /// </summary>
        [ConfigurationProperty("footprint",
            DefaultValue =
                CacheItemFootprint.MediumChangeFrequency | CacheItemFootprint.MediumCreationExpense |
                CacheItemFootprint.LowHeapRequirement, IsKey = false, IsRequired = true)]
        public CacheItemFootprint Footprint
        {
            get { return ((CacheItemFootprint) (base["footprint"])); }
            set { base["footprint"] = value; }
        }
    }
}